package com.smart.campus.controller;

import com.smart.campus.dto.ShTeachers;
import com.smart.campus.pojo.PagedResponse;
import com.smart.campus.pojo.ResponseResult;
import com.smart.campus.service.ShTeachersServiceFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ResourceBundle;

/**
 * @BelongsProject: smart-campus
 * @BelongsPackage: com.smart.campus.controller
 * @Author: JinBao shan
 * @date 2024/9/23 20:50
 * @Description: TODO
 * @Version: 1.0
 */

@Api(tags = "班主任管理模块")
@Slf4j
@RestController
@RequestMapping(value = "teachers")
public class ShTeachersController {
    @Autowired
    private ShTeachersServiceFeign teachersServiceFeign;

    @ApiOperation(value = "班主任列表分页查询",httpMethod = "POST",notes = "班主任列表分页查询")
    @RequestMapping(value = "findShTeachersPagination")
    public ResponseResult<PagedResponse<ShTeachers>> findShTeachersPagination(@RequestBody ShTeachers teachers, @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        return new ResponseResult<>(200,"班主任列表分页查询成功",teachersServiceFeign.findShTeachersPagination(teachers,pageNum,pageSize));
    }

    @ApiOperation(value = "班主任信息新增",httpMethod = "POST",notes = "班主任信息新增")
    @RequestMapping(value = "addShTeachers")
    public ResponseResult addShTeachers(@RequestBody ShTeachers teachers){
        try {
            teachersServiceFeign.addShTeachers(teachers);
            return new ResponseResult<>(200,"班主任信息新增成功");
        } catch (Exception e) {
            return new ResponseResult<>(444,"班主任信息新增失败");
        }
    }

    @ApiOperation(value = "班主任信息回显",httpMethod = "POST",notes = "班主任信息回显")
    @RequestMapping(value = "getShTeachersById")
    public ResponseResult<ShTeachers> getShTeachersById(@RequestBody ShTeachers teachers){
        System.out.println(teachers);
        return new ResponseResult<>(200,"班主任信息根据id查询成功",teachersServiceFeign.getShTeachersById(teachers));
    }

    @ApiOperation(value = "班主任信息修改",httpMethod = "POST",notes = "班主任信息修改")
    @RequestMapping(value = "updateShTeachersById")
    public ResponseResult updateShTeachersById(@RequestBody ShTeachers teachers){
        try {
            teachersServiceFeign.updateShTeachersById(teachers);
            return new ResponseResult<>(200,"班主任信息修改成功");
        } catch (Exception e) {
            return new ResponseResult<>(444,"班主任信息修改失败");
        }
    }

    @ApiOperation(value = "班主任信息删除",httpMethod = "POST",notes = "班主任信息删除")
    @RequestMapping(value = "deleteShTeachersById")
    public ResponseResult deleteShTeachersById(@RequestParam(value = "id") Integer id){
        try {
            teachersServiceFeign.deleteShTeachersById(id);
            return  new ResponseResult<>(200,"班主任信息删除成功");
        } catch (Exception e) {
            return new ResponseResult<>(444,"班主任信息删除失败");
        }
    }
}
